<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!--
    <script>
        var name="变";
        console.log(name) //控制台会输出 变
        function foo()
        {
            console.log(name); //在当前作用域里未给name 赋值则显示undefined
            var name="变化";
            console.log(name); //在当前作用域声明后 重新赋值后则输出变化
            
        }
        foo();
    </script>
    -->
    <!-- 
<script>

        var name="李四";
        function reWrite()
        {
            var name;
            console.log(name); //当前方法体内 显示Undefined 因为未重新赋值
            var name="李五"
            console.log(name); // 显示李五
        }
        reWrite();
        console.log(name);   // 结果显示为李四
    </script>
-->
    <!--

-->
    <!--
    <script>
        function fn() {
            var a
            if (true) {
                console.log(a)
            }
            else {
                var a = 1
                console.log(a)
            }
            var a =1
            console.log(a)
        }

        fn() // a -> undefined
    </script>
-->
    <script>
        {

            let a = 1
            console.log(a) // 输出 1
        }
        // console.log(a)   //如果未在同一块级 会报错 not defined未定义 应在块里输出
        {
            const b = 3;
            //const b=2;     //const 不能重复声明 且声明时就必须赋值，const是只读引用的
            console.log(b)
        }
        //console.log(b) 未在同一块级
    </script>
    <script>
        for (var i = 0; i < 10; i++) {
            setTimeout(function () {
                console.log(i);
            }, 100);
        }
        // 同一级内var循环向i重新赋值
    </script>
    <script>
        for (let i = 0; i < 10; i++) {
            setTimeout(function () {
                console.log(i);
            }, 100);
        }
        // let是修改并重新赋值循环打印0-9
    </script>

</body>

</html>